//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    cid:0,
    time:0
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function (p) {
    var that = this;

    var cid = p.cid 
    var time = p.time 
    that.setData({
      cid:cid,
      time:time
    })
    var menus = p.menus

    if (menus != undefined) {
      that.setData({
        menus: menus
      })
    }

    var mid = p.mid
    if (mid) {
      that.setData({
        mid: mid
      })
    }

    var searchqiye = wx.getStorageSync('searchqiye');
    that.setData({
      searchqiye: searchqiye
    })
   
  },
  getky: function (e) {
    var that = this;
    var ky = e.detail.value;
    that.setData({
      ky: ky
    })
  },

  schqiye: function () {
    var that=this
    var ky = that.data.ky
    if (typeof (ky) == 'undefined') {
      ky = ''
    }
      var searchqiye = wx.getStorageSync('searchqiye') || []


      var hasone = searchqiye.indexOf(ky)
      if (hasone !== -1) {
        searchqiye.splice(hasone, 1)

      }
      searchqiye.unshift(ky)
    if (ky != '') { wx.setStorageSync('searchqiye', searchqiye)}
      
    
      wx.redirectTo({
        url: '/pages/toocle/shop/search-result/search-result?cid=' + that.data.cid + '&time=' + that.data.time + '&terms=' + ky + '&menus=' + that.data.menus + "&mid=" + that.data.mid
      })
  },
  deleteHistory: function () {
    var that = this
    wx.showModal({
      title: '提示',
      content: '是否删除历史搜索',
      success: function (res) {
        if (res.confirm) {
          wx.setStorageSync('searchqiye', []);
          that.setData({
            searchqiye: []
          })

        }
      }
    })
  }
 
 



})
